<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>LangChain4j - 让Java应用拥有AI能力</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
        }
        .code-block {
            background-color: #2d2d2d;
            color: #f8f8f2;
            border-radius: 8px;
            overflow: hidden;
        }
        .icon-box {
            width: 60px;
            height: 60px;
            border-radius: 16px;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .highlight {
            position: relative;
        }
        .highlight:after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 30%;
            background-color: rgba(167, 119, 227, 0.2);
            z-index: -1;
            transform: scaleX(1.02);
        }
        .list-item {
            position: relative;
            padding-left: 1.75rem;
        }
        .list-item:before {
            content: '•';
            position: absolute;
            left: 0;
            color: #a777e3;
            font-weight: bold;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 md:py-32">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold mb-6 leading-tight">让Java应用<br>拥有AI对话能力</h1>
                    <p class="text-xl mb-8 opacity-90">LangChain4j为Java开发者架起通向AI世界的桥梁，轻松集成大语言模型到您的应用中</p>
                    <div class="flex flex-col sm:flex-row gap-4">
                        <a href="#get-started" class="bg-white text-purple-700 hover:bg-gray-100 font-medium py-3 px-6 rounded-lg transition duration-300 transform hover:-translate-y-1 shadow-lg">
                            <i class="fas fa-rocket mr-2"></i>快速开始
                        </a>
                        <a href="#examples" class="bg-transparent border-2 border-white hover:bg-white hover:bg-opacity-10 font-medium py-3 px-6 rounded-lg transition duration-300 transform hover:-translate-y-1">
                            <i class="fas fa-code mr-2"></i>查看示例
                        </a>
                    </div>
                </div>
                <div class="md:w-1/2 flex justify-center">
                    <img src="https://cdn.nlark.com/yuque/0/2025/png/21449790/1742267030651-edd6a0bf-3ad8-4cce-9235-632f46af295e.png" alt="LangChain4j架构图" class="rounded-xl shadow-2xl max-w-full h-auto" style="max-height: 300px;">
                </div>
            </div>
        </div>
    </section>

    <!-- Why LangChain4j Section -->
    <section id="why" class="py-16 px-4">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="text-center mb-16">
                <span class="inline-block px-4 py-1 bg-purple-100 text-purple-700 rounded-full text-sm font-semibold mb-3">核心价值</span>
                <h2 class="text-3xl md:text-4xl font-bold mb-4">为什么需要<span class="highlight">LangChain4j</span>？</h2>
                <p class="text-gray-600 max-w-2xl mx-auto">在ChatGPT掀起AI浪潮的今天，LangChain4j让传统Java应用也能"开口说话"，实现智能对话与文本生成</p>
            </div>

            <div class="grid md:grid-cols-3 gap-8">
                <div class="bg-white p-8 rounded-xl shadow-md card-hover">
                    <div class="icon-box bg-purple-100 text-purple-700 mb-6">
                        <i class="fas fa-code text-2xl"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">标准化API</h3>
                    <p class="text-gray-600">统一操作不同AI模型(GPT-3.5、Llama2等)，简化开发流程</p>
                </div>
                <div class="bg-white p-8 rounded-xl shadow-md card-hover">
                    <div class="icon-box bg-purple-100 text-purple-700 mb-6">
                        <i class="fas fa-comments text-2xl"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">对话管理</h3>
                    <p class="text-gray-600">自动维护聊天上下文，实现连贯的多轮对话体验</p>
                </div>
                <div class="bg-white p-8 rounded-xl shadow-md card-hover">
                    <div class="icon-box bg-purple-100 text-purple-700 mb-6">
                        <i class="fas fa-expand text-2xl"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">扩展性强</h3>
                    <p class="text-gray-600">支持自定义工具链开发，满足各类业务场景需求</p>
                </div>
            </div>

            <div class="mt-16 bg-white p-8 rounded-xl shadow-md">
                <div class="flex items-start">
                    <div class="flex-shrink-0 bg-purple-100 text-purple-700 rounded-lg p-3 mr-4">
                        <i class="fas fa-lightbulb text-2xl"></i>
                    </div>
                    <div>
                        <p class="text-gray-700 italic">"就像给Java应用装上了智能语音助手，让它能理解自然语言，完成智能问答、文本生成等任务。"</p>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Get Started Section -->
    <section id="get-started" class="py-16 px-4 bg-gray-100">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="text-center mb-12">
                <span class="inline-block px-4 py-1 bg-purple-100 text-purple-700 rounded-full text-sm font-semibold mb-3">快速上手</span>
                <h2 class="text-3xl md:text-4xl font-bold mb-4">准备你的<span class="highlight">AI工具箱</span></h2>
            </div>

            <div class="bg-white rounded-xl shadow-md overflow-hidden">
                <div class="p-6 border-b border-gray-200">
                    <h3 class="text-xl font-bold flex items-center">
                        <i class="fas fa-tools text-purple-600 mr-2"></i> 环境要求
                    </h3>
                    <ul class="mt-4 space-y-2">
                        <li class="list-item">JDK 17+（推荐Amazon Corretto）</li>
                        <li class="list-item">IntelliJ IDEA（2023.1+）</li>
                        <li class="list-item">OpenAI账号（或其他大模型API密钥）</li>
                    </ul>
                </div>
                <div class="p-6">
                    <h3 class="text-xl font-bold flex items-center">
                        <i class="fas fa-code text-purple-600 mr-2"></i> Maven依赖配置
                    </h3>
                    <div class="mt-4 code-block">
                        <pre class="p-4 overflow-x-auto"><code class="language-xml">&lt;dependency&gt;
    &lt;groupId&gt;dev.langchain4j&lt;/groupId&gt;
    &lt;artifactId&gt;langchain4j-open-ai&lt;/artifactId&gt;
    &lt;version&gt;0.25.0&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
&lt;/dependency&gt;</code></pre>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Integration Steps -->
    <section class="py-16 px-4">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="text-center mb-16">
                <span class="inline-block px-4 py-1 bg-purple-100 text-purple-700 rounded-full text-sm font-semibold mb-3">三步整合</span>
                <h2 class="text-3xl md:text-4xl font-bold mb-4">SpringBoot整合<span class="highlight">LangChain4j</span></h2>
            </div>

            <div class="grid md:grid-cols-3 gap-8">
                <div class="bg-white p-8 rounded-xl shadow-md card-hover">
                    <div class="flex items-center mb-4">
                        <div class="bg-purple-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-3">1</div>
                        <h3 class="text-xl font-bold">配置API密钥</h3>
                    </div>
                    <div class="code-block mt-4">
                        <pre class="p-4 text-sm overflow-x-auto"><code class="language-java">@Configuration
public class AiConfig {
    @Value("${openai.api.key}")
    private String apiKey;

    @Bean
    OpenAiChatModel openAiChatModel() {
        return OpenAiChatModel.builder()
                .apiKey(apiKey)
                .modelName("gpt-3.5-turbo")
                .temperature(0.3)
                .build();
    }
}</code></pre>
                    </div>
                </div>
                <div class="bg-white p-8 rounded-xl shadow-md card-hover">
                    <div class="flex items-center mb-4">
                        <div class="bg-purple-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-3">2</div>
                        <h3 class="text-xl font-bold">创建对话服务</h3>
                    </div>
                    <div class="code-block mt-4">
                        <pre class="p-4 text-sm overflow-x-auto"><code class="language-java">@Service
public class ChatService {
    private final OpenAiChatModel chatModel;

    public ChatService(OpenAiChatModel chatModel) {
        this.chatModel = chatModel;
    }

    public String chat(String message) {
        return chatModel.generate(message);
    }
}</code></pre>
                    </div>
                </div>
                <div class="bg-white p-8 rounded-xl shadow-md card-hover">
                    <div class="flex items-center mb-4">
                        <div class="bg-purple-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-3">3</div>
                        <h3 class="text-xl font-bold">构建REST接口</h3>
                    </div>
                    <div class="code-block mt-4">
                        <pre class="p-4 text-sm overflow-x-auto"><code class="language-java">@RestController
@RequestMapping("/api/ai")
public class AiController {
    private final ChatService chatService;

    public AiController(ChatService chatService) {
        this.chatService = chatService;
    }

    @PostMapping("/chat")
    public ResponseEntity&lt;String&gt; chat(@RequestBody String message) {
        return ResponseEntity.ok(chatService.chat(message));
    }
}</code></pre>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Practical Example -->
    <section id="examples" class="py-16 px-4 bg-gray-100">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="text-center mb-16">
                <span class="inline-block px-4 py-1 bg-purple-100 text-purple-700 rounded-full text-sm font-semibold mb-3">实战案例</span>
                <h2 class="text-3xl md:text-4xl font-bold mb-4">开发智能<span class="highlight">客服系统</span></h2>
            </div>

            <div class="mb-12">
                <h3 class="text-2xl font-bold mb-4 flex items-center">
                    <i class="fas fa-sitemap text-purple-600 mr-2"></i> 系统架构设计
                </h3>
                <div class="bg-white p-6 rounded-xl shadow-md">
                    <div class="mermaid">
                        graph LR
                            A[用户界面] --> B[SpringBoot服务]
                            B --> C[LangChain4j]
                            C --> D[OpenAI API]
                            D --> C
                            C --> B
                            B --> A
                    </div>
                </div>
            </div>

            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div>
                    <h3 class="text-2xl font-bold mb-4 flex items-center">
                        <i class="fas fa-list-check text-purple-600 mr-2"></i> 需求场景
                    </h3>
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-2"></i>
                            <span>订单状态查询</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-2"></i>
                            <span>退货政策咨询</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-2"></i>
                            <span>商品推荐</span>
                        </li>
                    </ul>
                </div>
                <div>
                    <h3 class="text-2xl font-bold mb-4 flex items-center">
                        <i class="fas fa-code text-purple-600 mr-2"></i> 增强版对话服务
                    </h3>
                    <div class="code-block">
                        <pre class="p-4 text-sm overflow-x-auto"><code class="language-java">public String handleInquiry(String userMessage) {
    String systemPrompt = """
        你是一位专业的电商客服助理，请根据以下规则回复：
        1. 当用户询问订单状态时，要求提供订单号
        2. 解释退货政策需引用条款第3章
        3. 推荐商品时优先推荐促销商品
        """;
    
    return chatModel.generate(
        userMessage + "\n[系统指令]：" + systemPrompt
    );
}</code></pre>
                    </div>
                </div>
            </div>

            <div class="bg-white p-8 rounded-xl shadow-md">
                <h3 class="text-2xl font-bold mb-6 flex items-center">
                    <i class="fas fa-vial text-purple-600 mr-2"></i> 效果演示
                </h3>
                <div class="code-block">
                    <pre class="p-4 text-sm overflow-x-auto"><code class="language-java">// 测试用例
@Test
void testOrderInquiry() {
    String response = chatService.handleInquiry("我的订单到哪里了？");
    assertTrue(response.contains("订单号"));
}

@Test
void testReturnPolicy() {
    String response = chatService.handleInquiry("商品不满意可以退吗？");
    assertTrue(response.contains("第3章"));
}</code></pre>
                </div>
            </div>
        </div>
    </section>

    <!-- Advanced Techniques -->
    <section class="py-16 px-4">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="text-center mb-16">
                <span class="inline-block px-4 py-1 bg-purple-100 text-purple-700 rounded-full text-sm font-semibold mb-3">高级技巧</span>
                <h2 class="text-3xl md:text-4xl font-bold mb-4">让AI更<span class="highlight">智能</span></h2>
            </div>

            <div class="grid md:grid-cols-3 gap-8">
                <div class="bg-white p-8 rounded-xl shadow-md card-hover">
                    <h3 class="text-xl font-bold mb-4 flex items-center">
                        <i class="fas fa-brain text-purple-600 mr-2"></i> 记忆管理
                    </h3>
                    <div class="code-block mt-4">
                        <pre class="p-4 text-sm overflow-x-auto"><code class="language-java">ChatMemory memory = new TokenWindowChatMemory(500);

UserMessage userMsg = new UserMessage("我喜欢科幻小说");
AssistantMessage assistantMsg = new AssistantMessage("好的，已记录您的喜好");
memory.add(userMsg);
memory.add(assistantMsg);</code></pre>
                    </div>
                </div>
                <div class="bg-white p-8 rounded-xl shadow-md card-hover">
                    <h3 class="text-xl font-bold mb-4 flex items-center">
                        <i class="fas fa-link text-purple-600 mr-2"></i> 链式调用
                    </h3>
                    <div class="code-block mt-4">
                        <pre class="p-4 text-sm overflow-x-auto"><code class="language-java">ModerationChain moderation = new ModerationChain(chatModel);
TranslationChain translation = new TranslationChain(chatModel);

String result = moderation.chain()
        .then(translation.toFrench())
        .execute("Hello world!");</code></pre>
                    </div>
                </div>
                <div class="bg-white p-8 rounded-xl shadow-md card-hover">
                    <h3 class="text-xl font-bold mb-4 flex items-center">
                        <i class="fas fa-scroll text-purple-600 mr-2"></i> 对话日志
                    </h3>
                    <div class="code-block mt-4">
                        <pre class="p-4 text-sm overflow-x-auto"><code class="language-java">@Aspect
@Component
public class ChatLogger {
    @Around("execution(* com.example.service.*.chat*(..))")
    public Object logChat(ProceedingJoinPoint joinPoint) throws Throwable {
        String input = (String) joinPoint.getArgs()[0];
        System.out.println("用户输入：" + input);
        
        Object output = joinPoint.proceed();
        
        System.out.println("AI回复：" + output);
        return output;
    }
}</code></pre>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Troubleshooting -->
    <section class="py-16 px-4 bg-gray-100">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="text-center mb-16">
                <span class="inline-block px-4 py-1 bg-purple-100 text-purple-700 rounded-full text-sm font-semibold mb-3">最佳实践</span>
                <h2 class="text-3xl md:text-4xl font-bold mb-4">避坑指南与<span class="highlight">性能优化</span></h2>
            </div>

            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <h3 class="text-2xl font-bold mb-4 flex items-center">
                        <i class="fas fa-bug text-purple-600 mr-2"></i> 常见问题排查
                    </h3>
                    <div class="space-y-4">
                        <div class="bg-white p-5 rounded-lg shadow-sm">
                            <h4 class="font-bold mb-2">超时问题</h4>
                            <p class="text-sm text-gray-600 mb-2">适当调整timeout参数</p>
                            <div class="code-block">
                                <pre class="p-3 text-xs overflow-x-auto"><code class="language-java">OpenAiChatModel.builder()
    .timeout(Duration.ofSeconds(30))</code></pre>
                            </div>
                        </div>
                        <div class="bg-white p-5 rounded-lg shadow-sm">
                            <h4 class="font-bold mb-2">中文乱码</h4>
                            <p class="text-sm text-gray-600">确保使用UTF-8编码</p>
                        </div>
                        <div class="bg-white p-5 rounded-lg shadow-sm">
                            <h4 class="font-bold mb-2">计费异常</h4>
                            <p class="text-sm text-gray-600">设置用量告警</p>
                        </div>
                    </div>
                </div>
                <div>
                    <h3 class="text-2xl font-bold mb-4 flex items-center">
                        <i class="fas fa-tachometer-alt text-purple-600 mr-2"></i> 性能优化方案
                    </h3>
                    <div class="space-y-4">
                        <div class="bg-white p-5 rounded-lg shadow-sm">
                            <h4 class="font-bold mb-2">缓存常用回答</h4>
                            <p class="text-sm text-gray-600">减少重复请求，降低API调用成本</p>
                        </div>
                        <div class="bg-white p-5 rounded-lg shadow-sm">
                            <h4 class="font-bold mb-2">异步处理长文本</h4>
                            <p class="text-sm text-gray-600">提升系统响应速度，避免阻塞</p>
                        </div>
                        <div class="bg-white p-5 rounded-lg shadow-sm">
                            <h4 class="font-bold mb-2">使用流式响应</h4>
                            <p class="text-sm text-gray-600 mb-2">改善用户体验，实现实时输出</p>
                            <div class="code-block">
                                <pre class="p-3 text-xs overflow-x-auto"><code class="language-java">@GetMapping("/stream")
public SseEmitter streamChat(@RequestParam String message) {
    SseEmitter emitter = new SseEmitter();
    chatModel.generateAsync(message)
        .onNext(emitter::send)
        .onComplete(emitter::complete);
    return emitter;
}</code></pre>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Footer -->
    <footer class="bg-gray-900 text-white py-10 px-4">
        <div class="container mx-auto max-w-5xl px-4 flex flex-col md:flex-row justify-between items-center">
            <div class="mb-4 md:mb-0">
                <h3 class="text-xl font-bold">技术小馆</h3>
                <p class="text-gray-400 mt-1">探索技术与创新</p>
            </div>
            <div>
                <a href="http://www.yuque.com/jtostring" class="text-purple-300 hover:text-white transition duration-300 flex items-center">
                    <i class="fas fa-globe mr-2"></i> 技术小馆地址
                </a>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
        
        // 平滑滚动
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
    </script>
</body>
</html>